using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Globalization;

public partial class SelectCulture : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //hide the flag that refers to the current culture
            switch (Thread.CurrentThread.CurrentUICulture.Name)
            {
                case "en-US":
                    imgUS.Visible = false;
                    break;
                case "es-ES":
                    imgES.Visible = false;                    
                    break;
                default:
                    imgBR.Visible = false;
                    break;
            }
        }
    }

    protected void imgBR_Click(object sender, ImageClickEventArgs e)
    {
        ChangeCulture(new CultureInfo("pt-BR"));
    }

    protected void imgES_Click(object sender, ImageClickEventArgs e)
    {
        ChangeCulture(new CultureInfo("es-ES"));
    }

    protected void imgUS_Click(object sender, ImageClickEventArgs e)
    {
        ChangeCulture(new CultureInfo("en-US"));
    }

    /// <summary>
    /// Change the culture and redirects to the same page to initialize the new choosen culture
    /// </summary>
    /// <param name="culture">CultureInfo object that represents the choosen culture</param>
    private void ChangeCulture(CultureInfo culture)
    {
        PageBase.SelectedCulture = culture;
        Response.Redirect(Request.UrlReferrer.ToString());
    }
}
